<?php
$class_name = "gestione_area";
?>var area = {
	status_change : function(id_record, nuovo_stato){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/status_change/"?>' + id_record +"/"+ nuovo_stato , 
			type : 'POST' ,
			success : function(html){
				if(html=="1"){
					area.list(); 
				}
				else alert(html); 
			}
		});
	} , 
	delete : function(id_record){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/delete/"?>' + id_record , 
			type : 'POST' ,
			success : function(html){
				if(html=="1"){
					area.list(); 
				}
				else alert(html); 
			}
		});
	},
	form_insert : function(){
		if(!$('#operazioni_aree').html()){
			$.ajax({
				cache : false , 
				url : '<?php echo base_url().$class_name."/form_inserisci"?>' , 
				type : 'POST' ,
				success : function(html){
					$('#operazioni_aree').html(html);
					$('#insert_button').button();
				}
			});
		}
		else $('#operazioni_aree').html('')
	} ,
	
	modify_db : function(id_record){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/modify_db/"?>' + id_record , 
			type : 'POST' ,
			data : $('#form_area_mod_'+id_record).serialize() ,
			success : function(html){
				if(html=="1"){
					area.list();
				}
				else alert(html);
				
			}
		});
	}
	,
	modify : function(id_record){
		if(!$('#operazioni_area_' + id_record).html()){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/modify/"?>' + id_record , 
			type : 'POST' ,
			success : function(html){
				$('#operazioni_area_' + id_record).html(html);
				$('#modify_button').button();
			}
		});
		}
		else {
			$('#operazioni_area_' + id_record).html('');
		}
	} ,  
	form_insert_db : function(){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/inserisci_area_db"?>' , 
			type : 'POST' ,
			data : $('#form_area_ins').serialize() ,
			success : function(html){
				if(html=="1"){
					$('#operazioni_aree').html('');
					area.list();
				}
				else alert(html);
			}
		})
	} ,  
	list : function(){
		$.ajax({
			cache : false , 
			url : '<?php echo base_url().$class_name."/elenco"?>' , 
			type : 'POST' ,
			success : function(html){
				$("#area_list").html(html);
			}
		});
	}
	,
	init : function(){
		this.list();
	}
}
